package com.simpletaskapp.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import com.simpletaskapp.R;
import com.simpletaskapp.domain.Task;

public class EditTask extends AbstractTaskActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (savedInstanceState == null)
			task = (Task) getIntent().getExtras().getSerializable("TASK");

		descriptionEditText.setText(task.getDescription());
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		if (item.getItemId() == R.id.trashTask) {
			Toast.makeText(this, getString(R.string.deleted),
					Toast.LENGTH_SHORT).show();
			taskDAO.deleteTask(task);
			this.finish();
		}

		return super.onOptionsItemSelected(item);
	}

	@Override
	protected String getDisplayTitle() {
		return getString(R.string.editTask);
	}

	@Override
	protected int getMenuResource() {
		return R.menu.task_edit_menu;
	}
}